<template ref="datadictForm">
  <div class="app-container">
    <el-form :model="queryParams2" ref="queryForm2" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="数据编码" prop="tableName">
        <el-input style="width: 300px" disabled="true"
                  v-model="queryParams2.tableName"
                  placeholder="请输入基础数据编码"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="编码名称" prop="tableName">
        <el-input style="width: 300px" disabled="true"
                  v-model="queryParams2.chineseName"
                  placeholder="请输入基础数据编码名称"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item v-if="hisVersionVal" label="版本号" prop="hisVersionVal">
        <el-input disabled="true"
                  v-model="queryParams2.hisVersionVal"
                  placeholder="请输入版本号"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
    </el-form>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="所属模块" prop="strModular">
        <treeselect style="width: 300px;" v-model="queryParams.strModular" :show-count="true"
                    :multiple="true"
                    :disable-branch-nodes="true"
                    @keyup.enter.native="handleQuery"
                    :options="modularTree"  placeholder="请选择所属模块" />
      </el-form-item>
      <el-form-item label="所属报表" prop="strReport">
        <treeselect style="width: 300px;" v-model="queryParams.strReport" :show-count="true"
                    :multiple="true"
                    :disable-branch-nodes="true"
                    @keyup.enter.native="handleQuery"
                    :options="reportTree"  placeholder="请选择所属报表" />
      </el-form-item>
      <el-form-item label="所属客户" prop="strCustomer">
        <treeselect style="width: 300px;" v-model="queryParams.strCustomer" :show-count="true"
                    :multiple="true"
                    :disable-branch-nodes="true"
                    @keyup.enter.native="handleQuery"
                    :options="customerTree"  placeholder="请选择所属客户" />
      </el-form-item>
      <el-form-item label="版本号" prop="rwDbVersion">
        <el-select v-model="queryParams.rwDbVersion" placeholder="请选择版本号" clearable>
          <el-option
            v-for="dict in dict.type.report_version"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
            @keyup.enter.native="handleQuery"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="状态" prop="rwDbStatus">
        <el-select v-model="queryParams.rwDbStatus" placeholder="请选择状态" clearable>
          <el-option
            v-for="dict in dict.type.sys_common_status"
            :key="dict.value"
            :label="dict.label"
            :value="parseInt(dict.value)"
            @keyup.enter.native="handleQuery"
          />
        </el-select>
      </el-form-item>
    </el-form>

    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <!--<el-form-item label="历史版本" prop="hisVersion">
        <el-select @change="changeHisVersion($event)" v-model="queryParams.hisVersion" placeholder="请选择历史版本号" clearable>
          <el-option
            v-for="dict in hisVersions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
            @keyup.enter.native="handleQuery"
          ></el-option>
        </el-select>
      </el-form-item>-->
        <el-form-item v-show="showSearchColl" v-for="(item, index) in headList"  v-if=" item.isQuery == 1" :label="item.label" :key="index" :prop="item.prop">
          <el-input  @keyup.enter.native="handleQuery" clearable v-if="item.componentType == 'input'" :placeholder="'请输入'+item.label" v-model="queryParams[item.prop]"></el-input>
          <el-select @keyup.enter.native="handleQuery" clearable v-if="item.componentType == 'select'" :placeholder="'请选择'+item.label" v-model="queryParams[item.prop]">
            <el-option
              v-for="dict in item.options"
              :key="dict.keyId"
              :label="dict.keyName"
              :value="dict.keyId"
            />
          </el-select>
          <el-input-number @keyup.enter.native="handleQuery" clearable style="width:100%" v-if="item.componentType == 'inputnumber'"
                           v-model="queryParams[item.prop]"
                           controls-position="right" :min="0"/>
          <el-date-picker @keyup.enter.native="handleQuery" clearable  v-if="item.componentType == 'date'"
                          v-model="queryParams[item.prop]"
                          type="date"
                          value-format="yyyy-MM-dd">
          </el-date-picker>
          <el-date-picker @keyup.enter.native="handleQuery" clearable  v-if="item.componentType == 'datetime'"
                          v-model="queryParams[item.prop]"
                          type="datetime"
                          value-format="yyyy-MM-dd HH:mm:ss">
          </el-date-picker>

        </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['reportworld:database:data:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate('')"
          v-hasPermi="['reportworld:database:data:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="multiple"
          @click="handleUpdateBatch"
          v-hasPermi="['reportworld:database:data:batchEdit']"
        >批量修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['reportworld:database:data:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleCopy"
          v-hasPermi="['reportworld:database:data:copy']"
        >复制</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['reportworld:database:data:execl']"
        >导出EXECL</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="dataBaseSql"
          v-hasPermi="['reportworld:database:data:sql']"
        >导出SQL</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-close"
          size="mini"
          @click="handleClose"
        >关闭</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" :showSearchColl.sync="showSearchColl" :searchColl="searchColl" @queryTable="getList"></right-toolbar>
    </el-row>



      <el-table max-height="550px"
        :data="tableData"
        ref="table"
        border="border"
        v-loading="loading"
        @sort-change="handleSortChange"
        :row-style="tableRowStyle"
        @selection-change="handleSelectionChange"
        @row-click="rowClick"
         >
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column v-hasPermi="['reportworld:database:data:query','reportworld:database:data:demandBug','reportworld:detail:data:comparedata']"
          label="操作" align="center" width="200" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-view"
              @click="handleUpdate(scope.row,false)"
              v-hasPermi="['reportworld:database:data:query']"
            >详情</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="detailDemandBug(scope.row)"
              v-hasPermi="['reportworld:detail:demandBug']"
            >修改记录</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="comparedata(scope.row)"
              v-hasPermi="['reportworld:detail:data:comparedata']"
            >历史记录</el-button>
           <!-- <el-dropdown size="mini" @command="(command) => handleCommand(command, scope.row)" v-hasPermi="['reportworld:database:data:demandBug','reportworld:database:data:comparedata']">
              <el-button size="mini" type="text" icon="el-icon-d-arrow-right">更多</el-button>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item  command="databaseDemandBug" icon="el-icon-edit"
                                   v-hasPermi="['reportworld:database:data:demandBug']">修改记录</el-dropdown-item>
                <el-dropdown-item  command="comparedata" icon="el-icon-edit"
                                   v-hasPermi="['reportworld:database:data:comparedata']">历史记录</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>-->
          </template>
        </el-table-column>
        <el-table-column v-for="item in headList"
                         align="center"
                         show-overflow-tooltip
                         :width="item.width"
                         :prop="item.prop"
                         :key="item.id"
                         :label="item.label"
                         :sortable="'custom'" :sort-orders="['descending', 'ascending']">
            <template slot-scope="scope" >
                      <a @click="handleDataDictDetail(scope.row.SELECT_LIST)" style="color:blue;cursor:pointer;font-size: 12px;"
                         v-if="item.tableName == 'RW_DB_TP_REP_FUNC_INFO' && item.prop == 'SELECT_LIST'
                         && scope.row.COLUM_TYPE =='VARCHAR2' && scope.row.VIEW_TYPE =='2' ">{{
                        scope.row[`${item.prop}`] }}
                      </a>
                      <a @click="handleDataDictDetail(scope.row.CLASS_ID)" style="color:blue;cursor:pointer;font-size: 12px;"
                         v-else-if="item.tableName =='RW_DB_TP_GL_EXHIB_DATADICT' && item.prop == 'CLASS_ID'">{{
                        scope.row[`${item.prop}`] }}
                      </a>
                      <span v-else>{{ scope.row[`${item.prop}`] }}</span>

            </template>
      </el-table-column>
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"/>

    <el-dialog  v-if="dialogVisible" :title="title" :close-on-click-modal ="false" :visible.sync="dialogVisible" width="1000px"  append-to-body >
        <el-form :model="addOrUpdateForm" ref="addOrUpdateForm" label-width="150px" :rules="rules">
          <el-row>
         <header :style="[{height:(batchEdit== true ?'500px':'230px')},{overflow:'auto'}]">
           <el-col :span="24">
             <el-form-item label="所属模块" prop="MODULAR">
               <treeselect v-model="addOrUpdateForm.MODULAR"
                           :show-count="true"
                           :multiple="true"
                           :disable-branch-nodes="true"
                           :options="modularTree"
                           placeholder="请选择所属模块"/>
             </el-form-item>
           </el-col>
           <el-col v-if="batchEdit== true" :span="12">
             <el-form-item label="清空所属模块" prop="clearModular">
               <el-switch v-model="addOrUpdateForm.clearModular"></el-switch>
             </el-form-item>
           </el-col>
           <el-col :span="24">
             <el-form-item label="所属报表" prop="REPORT">
               <treeselect v-model="addOrUpdateForm.REPORT"
                           :show-count="true"
                           :multiple="true"
                           :disable-branch-nodes="true"
                           :options="reportTree"
                           placeholder="请选择所属报表"/>
             </el-form-item>
           </el-col>
           <el-col v-if="batchEdit== true" :span="12">
             <el-form-item label="清空所属报表" prop="clearReport">
               <el-switch v-model="addOrUpdateForm.clearReport"></el-switch>
             </el-form-item>
           </el-col>
           <el-col :span="24">
             <el-form-item label="所属客户" prop="CUSTOMER">
               <treeselect v-model="addOrUpdateForm.CUSTOMER"
                           :show-count="true"
                           :multiple="true"
                           :disable-branch-nodes="true"
                           :options="customerTree"
                           placeholder="请选择所属客户"/>
             </el-form-item>
           </el-col>
           <el-col v-if="batchEdit== true" :span="12">
             <el-form-item label="清空所属客户" prop="clearCustomer">
               <el-switch v-model="addOrUpdateForm.clearCustomer"></el-switch>
             </el-form-item>
           </el-col>
           <el-col v-if="batchEdit== false" :span="12">
             <el-form-item label="版本号" prop="RW_DB_VERSION">
               <el-select :disabled="true" clearable v-model="addOrUpdateForm.RW_DB_VERSION" placeholder="请选择版本号">
                 <el-option
                   v-for="dict in dict.type.report_version"
                   :key="dict.value"
                   :label="dict.label"
                   :value="dict.value"
                 ></el-option>
               </el-select>
             </el-form-item>
           </el-col>
           <el-col v-if="batchEdit== true" :span="12">
             <el-form-item label="状态" prop="RW_DB_STATUS">
               <el-select clearable v-model="addOrUpdateForm.RW_DB_STATUS" placeholder="请选择状态">
                 <el-option
                   v-for="dict in dict.type.sys_common_status"
                   :key="dict.value"
                   :label="dict.label"
                   :value="parseInt(dict.value)"
                 ></el-option>
               </el-select>
             </el-form-item>
           </el-col>
           <el-col v-if="batchEdit== false" :span="12">
             <el-form-item label="状态" prop="RW_DB_STATUS">
               <el-radio-group v-model="addOrUpdateForm.RW_DB_STATUS">
                 <el-radio
                   v-for="dict in dict.type.sys_common_status"
                   :key="dict.value"
                   :label="parseInt(dict.value)"
                 >{{dict.label}}
                 </el-radio>
               </el-radio-group>
             </el-form-item>
           </el-col>
          </header>

          <div v-if="batchEdit == false" style="height:300px;overflow:auto;">
            <el-col  :span="(item.width > 300 || item.componentType == 'monaco' || item.componentType == 'textarea') ? 24 :12 "
                    v-for="(item, index) in headList" :key="index">
              <el-form-item v-if="item.componentType && batchEdit== false"  :label="item.label" :prop="item.prop">
                <el-input clearable  v-if="item.componentType == 'input'" v-model="addOrUpdateForm[item.prop]"></el-input>
                <el-date-picker clearable  v-if="item.componentType == 'date'"
                                v-model="addOrUpdateForm[item.prop]"
                                type="date"
                                value-format="yyyy-MM-dd">
                </el-date-picker>
                <el-date-picker clearable  v-if="item.componentType == 'datetime'"
                                v-model="addOrUpdateForm[item.prop]"
                                type="datetime"
                                value-format="yyyy-MM-dd HH:mm:ss">
                </el-date-picker>
                <el-select clearable  v-if="item.componentType == 'select'" v-model="addOrUpdateForm[item.prop]">
                  <el-option
                    v-for="dict in item.options"
                    :key="dict.keyId"
                    :label="dict.keyName"
                    :value="dict.keyId"
                  />
                </el-select>
                <el-radio-group  v-if="item.componentType == 'radio'" v-model="addOrUpdateForm[item.prop]">
                  <el-radio
                    v-for="dict in item.options"
                    :key="dict.value"
                    :label="dict.value"
                  >{{dict.label}}
                  </el-radio>
                </el-radio-group>
                <monaco-editor  v-if="item.componentType == 'monaco'"  ref="monacoEditor"  style="border:1px solid #000;"
                               :opts="opts"></monaco-editor>
                <textarea v-if="item.componentType == 'textarea'" style="width:100%;height: 292px" v-model="addOrUpdateForm[item.prop]"></textarea>
                <editor v-if="item.componentType == 'editor'" v-model="addOrUpdateForm[item.prop]" :min-height="192"/>
                <el-input-number clearable style="width:100%" v-if="item.componentType == 'inputnumber'"
                                 v-model="addOrUpdateForm[item.prop]"
                                 controls-position="right" :min="0"/>
              </el-form-item>
            </el-col>
          </div>
          </el-row>
        </el-form>
      <span slot="footer" class="dialog-footer">
            <el-button type="primary" v-if="isUpdate" :loading="butloading" @click="submitForm">确 定</el-button>
            <el-button @click="dialogVisible = false">取 消</el-button>
        </span>
    </el-dialog>

    <!-- 导出选择数据库类型 -->
    <el-dialog :title="titleDatabaseType" :close-on-click-modal ="false" :visible.sync="openDatabaseType" width="500px" height="100px" append-to-body>
      <el-form ref="formDatabaseType" :model="formDatabaseType" :rules="rulesDatabaseType"  label-width="100px">
        <el-row>
          <el-col :span="24" style="height:100px ">
            <el-form-item label="数据库类型" prop="dataBaseType">
              <el-select clearable v-model="formDatabaseType.dataBaseType"
                         placeholder="请选择数据库类型">
                <el-option
                  v-for="dict in dict.type.report_database_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary"  @click="submitDataBaseSql">确 定</el-button>
        <el-button @click="openDatabaseType = false">关 闭</el-button>
      </div>
    </el-dialog>

    <el-dialog  :title="titleDict" :close-on-click-modal ="false"  :visible.sync="openDict" width="1000px" append-to-body>
      <datadict :classId="classId" :hisVersion="hisVersion"> </datadict >
      <div slot="footer" class="dialog-footer">
        <el-button @click="openDict = false">关 闭</el-button>
      </div>
    </el-dialog>

    <el-dialog v-if="openComparedata" :title="titleComparedata" :close-on-click-modal ="false"  :visible.sync="openComparedata" width="1200px" append-to-body>
      <compare :dataId="dataId" :dataCode="dataCode"> </compare>
      <div slot="footer" class="dialog-footer">
        <el-button @click="openComparedata = false">关 闭</el-button>
      </div>
    </el-dialog>

    <el-dialog v-if="openDatademandbug" :title="titleDatademandbug" :close-on-click-modal ="false"  :visible.sync="openDatademandbug" width="1200px" append-to-body>
      <datademandbug :dataId="dataId" :dataCode="dataCode" :hisVersion="hisVersion"> </datademandbug>
      <div slot="footer" class="dialog-footer">
        <el-button @click="openDatademandbug = false">关 闭</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
  import { getDataBaseInfo,addDataBaseInfo,updateDataBaseInfo,removeDataBaseInfo,handleUpdateBatch,dataBaseSql} from "@/api/reportworld/database";
  import { getDatabaseByCode} from "@/api/reportworld/database";
  import { getTableRowStyle } from "@/utils/yss";
  import Treeselect from "@riophae/vue-treeselect";
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  import monacoEditor from '@/components/SqlEditor';
  import datadict from "@/views/reportworld/datadict/index";
  import compare from "@/views/reportworld/comparedata/index";
  import datademandbug from "@/views/reportworld/demandbuginfo/datademandbug";

  export default {
    name: "DataBaseInfo",
    components: {
      Treeselect,
      monacoEditor,
      datadict,
      compare,
      datademandbug
    },
    dicts: ['sys_common_status', 'report_version','report_database_type'],
    data() {
      return {
        butloading:false,
        isUpdate:false,
        hisVersionVal:false,
        queryParams:{
          pageNum: 1,
          pageSize: 50,
          rwDbVersion: null,
          rwDbStatus: null,
          strModular:[],
          strCustomer:[],
          strReport:[],
          hisVersion:null,
          code:null
        },
        queryParams2:{},
        opts: { //编辑器
          value: '',
          readOnly: false, // 是否可编辑
          language: 'sql', // 语言类型
          theme: 'vs', // 编辑器主题
          lineNumbers: "on", // 行号 取值
        },
        // 传递字典编码
        classId: '',
        // 字典弹出层
        openDict:false,
        titleDict:'',
        //历史数据
        titleComparedata:'',
        openComparedata:false,
        titleDatademandbug:'',
        openDatademandbug:false,
        dataId:'',
        dataCode:'',
        // 遮罩层
        loading: true,
        // 显示搜索条件
        showSearch: true,
        searchColl:true,
        showSearchColl:false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 总条数
        total: 0,
        //所属模块
        modularTree : [],
        // 所属客户
        customerTree: [],
        //所属报表
        reportTree: [],
        // 历史版本
        hisVersions:[],
        hisVersion:'',
        // 弹出层标题
        title: "",
        dialogVisible: false,
        //列数
        collen: 2,
        //原始列头
        formList: [],
        //展示的列头
        headList: [],
        //表格内容
        tableData: [],
        //校验规则
        rules: {},
        // 批量修改需要隐藏的字段
        batchEdit: false,
        //编辑行数据
        addOrUpdateForm: {},
        updateSelection:[],
        // 导出SQL语句弹出
        titleDatabaseType: "",
        openDatabaseType:false,
        formDatabaseType:{},
        rulesDatabaseType:{
          dataBaseType:[{ required: true, message: '请选择数据库类型',trigger: 'blur'}]
        }
      };
    },
    created() {
    },
    activated() {
      const code = this.$route.query.code;
      const hisVersion = this.$route.query.hisVersion;
      if(code != undefined && code){
        this.queryParams.code = code;
        this.queryParams.hisVersion = hisVersion;
        this.hisVersionVal = false;
        if (this.queryParams.hisVersion) {
          this.hisVersionVal = true;
          this.queryParams2.hisVersionVal = this.queryParams.hisVersion;
        }
        this.getDatabaseByCode();
        // this.init();
        this.getList();
      }
    },
   mounted(){
     /* for(let i=0;i<this.formList2;i++){
        this.formList.push({
          id: '1111'+i,
          sort: i,
          required: 1,
          show: 1,
          prop: "column"+i,
          label: "名称"+i
        })
      };
      this.total= this.queryParams.total;
      for(let i=0;i<this.queryParams.total;i++){
         this.tableData[i] = {id: i};
        for(let j=0;j<this.formList.length;j++){
          this.tableData[i][this.formList[j].prop] =  i+"_"+j
        }
      }
      this.headList = [];
      this.formList.map(x=>{
        if(x.show==1){
        this.headList.push(x);
      }
    })
      this.headList = Object.assign([],this.headList)
      this.$nextTick(() => {
        this.$refs.table.doLayout();
    })*/
    },
    methods: {
      init(){
        this.$set(this.queryParams, "strModular", null);
        this.$set(this.queryParams, "strCustomer", null);
        this.$set(this.queryParams, "strReport", null);
      },
      getDatabaseByCode(){
        getDatabaseByCode(this.queryParams.code,this.queryParams.hisVersion).then(response => {
          this.queryParams2.tableName=response.data.code.replace('RW_DB_','');
          this.queryParams2.chineseName=response.data.name;
          if(this.queryParams.hisVersion){
            this.hisVersionVal=true;
            this.queryParams2.hisVersionVal=this.queryParams.hisVersion;
        }
      });
      },
     /* changeHisVersion(value){
        this.queryParams.hisVersion=value;
        this.init();
        this.getList();
      },*/
      /** 查询报表世界字典列表 */
      getList() {
        this.loading = true;
        getDataBaseInfo(JSON.stringify(this.queryParams)).then(response => {
          this.formList=response.formList;
          this.total = response.total;
          this.tableData=response.rows;
          this.modularTree=response.modularTree;
          this.customerTree=response.customerTree;
          this.reportTree=response.reportTree;
          this.hisVersions=response.hisVersions;
          this.headList = [];
          this.formList.map(x=>{
            if(x.isShow==1){
            this.headList.push(x);
          }
         })
          this.headList = Object.assign([],this.headList)
          this.$nextTick(() => {
            this.$refs.table.doLayout();
        })
          this.loading = false;
      });
      },
      /** 字典信息 */
      handleDataDictDetail: function(classId) {
        this.openDict =true;
        this.classId = classId;
        this.hisVersion=this.queryParams.hisVersion;
        this.titleDict = "字典详细信息";
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 返回按钮操作 */
      handleClose() {
        const obj = { path: "/reportworld/dataInfo/database" };
        this.$tab.closeOpenPage(obj);
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.RW_DB_ID);
        this.single = selection.length!==1
        this.multiple = !selection.length
        this.updateSelection =selection[0];
      },
      /** 排序触发事件 */
      handleSortChange(column, prop, order) {
        this.queryParams.orderByColumn = column.prop;
        this.queryParams.isAsc = column.order;
        this.getList();
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.title = "添加基础数据";
        this.rules = {};
        this.opts.value= '';
        const equalToDataSql = (rule, value, callback) => {
          if (this.$refs.monacoEditor[0].getVal()) {
            callback()
          } else {
            callback(new Error("不能为空"));
          }
        };
        this.headList.map(x=>{
          this.rules[x.prop] = [];
        if(x.required == 1){
          if(x.componentType == 'monaco'){
            this.rules[x.prop].push({required: true,message: '请输入'+x.label,trigger: 'blur', validator: equalToDataSql})
          }else{
            this.rules[x.prop].push({required: true,message: '请输入'+x.label,trigger: 'blur'})
          }
        }
      });
        this.addOrUpdateForm = {};
        this.addOrUpdateForm.RW_DB_VERSION = this.dict.type.report_version[0].value;
        if(this.queryParams.hisVersion){
          this.addOrUpdateForm.RW_DB_VERSION =this.queryParams.hisVersion;
        }
        this.addOrUpdateForm.RW_DB_STATUS = parseInt(this.dict.type.sys_common_status[0].value);
        this.dialogVisible = true;
        this.batchEdit=false;
        this.isUpdate =true;
      },
      /** 修改按钮操作 */
      handleUpdate(row,isUpdate) {
        this.title = "修改基础数据";
        this.rules = {};
        const equalToDataSql = (rule, value, callback) => {
          if (this.$refs.monacoEditor[0].getVal()) {
            callback()
          } else {
            callback(new Error("不能为空"));
          }
        };
        this.headList.map(x=>{
          this.rules[x.prop] = [];
        if(x.required == 1){
          if(x.componentType == 'monaco'){
            this.rules[x.prop].push({required: true,message: '请输入'+x.label,trigger: 'blur', validator: equalToDataSql})
          }else{
            this.rules[x.prop].push({required: true,message: '请输入'+x.label,trigger: 'blur'})
          }
        }
      });
        this.opts.value= '';
        if(row){
          this.addOrUpdateForm = Object.assign({},row);
          this.headList.map(x=>{
           if(x.componentType == 'monaco'){
              this.opts.value= row[x.prop];
          }
          });
        }else{
          this.addOrUpdateForm = Object.assign({},this.updateSelection);
          this.headList.map(x=>{
            if(x.componentType == 'monaco'){
            this.opts.value= this.updateSelection[x.prop];
          }
        });
        }
        this.dialogVisible = true;
        this.batchEdit=false;
        this.isUpdate =true;
        if(isUpdate == false){
          this.title = "基础数据详情";
          this.isUpdate =false;
        }
      },
      /** 复制操作 */
      handleCopy(row) {
        this.handleAdd();
        this.rules = {};
        const equalToDataSql = (rule, value, callback) => {
          if (this.$refs.monacoEditor[0].getVal()) {
            callback()
          } else {
            callback(new Error("不能为空"));
          }
        };
        this.headList.map(x=>{
          this.rules[x.prop] = [];
        if(x.required == 1){
          if(x.componentType == 'monaco'){
            this.rules[x.prop].push({required: true,message: '请输入'+x.label,trigger: 'blur', validator: equalToDataSql})
          }else{
            this.rules[x.prop].push({required: true,message: '请输入'+x.label,trigger: 'blur'})
          }
        }
      });
        this.opts.value= '';
        this.addOrUpdateForm = Object.assign({},this.updateSelection);
        this.headList.map(x=>{
          if(x.componentType == 'monaco'){
          this.opts.value= this.updateSelection[x.prop];
        }
      });
        this.addOrUpdateForm['RW_DB_ID'] = null;
        this.form.version = this.dict.type.report_version[0].value;
        if(this.queryParams.hisVersion){
          this.form.version =this.queryParams.hisVersion;
        }
      },
      handleUpdateBatch(row) {
        this.addOrUpdateForm = {};
        this.dialogVisible = true;
        this.title = "批量修改基础数据";
        this.rules = {};
        this.batchEdit=true;
        this.isUpdate =true;
      },
     /* detailDemandBug(row){
        this.$router.push({ name:'dataDemandBug',query: {dataId:row.RW_DB_ID,dataCode:this.queryParams.code} });
     },*/
      detailDemandBug(row) {
        this.openDatademandbug =true;
        this.dataId = row.RW_DB_ID;
        this.dataCode = this.queryParams.code;
        this.hisVersion=this.queryParams.hisVersion;
        this.titleDatademandbug = "基础数据修改记录信息";
      },
      comparedata(row){
        this.openComparedata =true;
        this.dataId = row.RW_DB_ID;
        this.dataCode = this.queryParams.code;
        this.hisVersion=this.queryParams.hisVersion;
        this.titleComparedata = "基础数据历史记录信息";
      },
      /**修改记录*/
    /*  handleCommand(command, row){
        switch (command) {
          case "databaseDemandBug":
            this.$router.push({ name:'dataDemandBug',query: {dataId:row.RW_DB_ID,dataCode:this.queryParams.code} });
            break;
          case "comparedata":
            this.handleComparedata(row.RW_DB_ID,this.queryParams.code);
            break;
          default:
            break;
        }
      },*/
      submitForm() {
        if(this.batchEdit==false){
          this.headList.map(x=>{
            if(x.componentType == 'monaco'){
            this.addOrUpdateForm[x.prop] = this.$refs.monacoEditor[0].getVal();
          }
        });
        }
        this.$refs["addOrUpdateForm"].validate((valid) => {
          if (valid) {
            this.butloading=true;
            this.addOrUpdateForm['RW_DB_CODE']= this.queryParams.code
            this.addOrUpdateForm['hisVersion'] = this.queryParams.hisVersion;
            if(this.batchEdit==true){
              this.addOrUpdateForm["ids"] = this.ids;
              handleUpdateBatch(this.addOrUpdateForm).then(response => {
                this.$modal.msgSuccess("修改成功");
              this.dialogVisible = false;
              this.getList();
            }).finally(() => {this.butloading=false});
            }else if(this.addOrUpdateForm['RW_DB_ID'] != null){
              updateDataBaseInfo(JSON.stringify(this.addOrUpdateForm)).then(response => {
                this.$modal.msgSuccess("修改成功");
              this.dialogVisible = false;
              this.getList();
            }).finally(() => {this.butloading=false});
             }else{
              addDataBaseInfo(JSON.stringify(this.addOrUpdateForm)).then(response => {
                this.$modal.msgSuccess("新增成功");
              this.dialogVisible = false;
              this.getList();
            }).finally(() => {this.butloading=false});
            }
          }
      });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const object = Object.assign({});
        if(row){
          this.ids.push(row.RW_DB_ID)
        }
        object.ids= this.ids;
        object.RW_DB_CODE =this.queryParams.code;
        object.hisVersion=this.queryParams.hisVersion;
        this.$modal.confirm('是否确认删除数据项？').then(function() {
          return removeDataBaseInfo(JSON.stringify(object));
        }).then(() => {
          this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.queryParams.ids=JSON.stringify(this.ids);
        this.download('reportworld/database/exportData', {
          ...{"queryJson":JSON.stringify(this.queryParams)}
      }, this.queryParams.code.replace('RW_DB_','') + `${new Date().getTime()}.xlsx`)
      },
      dataBaseSql(){  // 导出选择数据库
        this.openDatabaseType=true;
        this.titleDatabaseType ="导出SQL语句";
      },
      submitDataBaseSql(){
        this.$refs["formDatabaseType"].validate(valid => {
          if (valid) {
            this.openDatabaseType=false;
            this.queryParams.DATABASETYPE =this.formDatabaseType.dataBaseType;
            this.queryParams.ids=JSON.stringify(this.ids);
            this.download('reportworld/database/dataBaseSql', {
              ...{"queryJson":JSON.stringify(this.queryParams)}
          }, `${new Date().getTime()}.sql`)
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      },
      tableRowStyle({row, rowIndex}){
        return getTableRowStyle(row,rowIndex,this.ids);
      },
      rowClick(row, column, event) { //单击行
        this.$refs.table.toggleRowSelection(row);
      }
    },
  };
</script>

